#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   conftest.py
@Time    :   2022/02/23 09:16:36
@Author  :   WangWei 
@Version :   1.0
@Contact :   wangwei@chengtech.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''
import sys
import os
import logging
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.abspath(os.path.dirname(curPath) + os.path.sep + ".")
sys.path.append(rootPath)
sys.path.append(os.path.join(curPath,'commDriver'))
sys.path.append(os.path.join(curPath,'data'))


# here put the import lib
import pytest
import sys
import os
import time
import datetime
import allure
from py._xmlgen import html
import traceback

# from commDriver.CAN import *
from commDriver.TS_CAN import *
from commDriver.power import *
from project_CAN import *

import Set_up

__Driver = {}

sys.dont_write_bytecode = True

# 这里我设置的级别是模块级别，也就是每个测试文件运行一次
# 可以设置为session，全部用例执行一次
@pytest.fixture(scope='session')
def Driver():
    # global __Driver

    # Init CAN Tool
    try:
        logging.info("open CAN_Driver".center(50, '-'))
        # project_rbs = real_CAN(Set_up.drive_type,Set_up.configure_baudrate)
        project_rbs = real_CAN(Set_up.drive_type,Set_up.configure_baudrate,totle_channel_count=2)
        project_rbs2 = real_CAN(Set_up.drive_type,Set_up.configure_baudrate2,TSMasterAPI.CHANNEL_INDEX.CHN2)
        project_rbs.load_dbc(Set_up.project_DBC_File_CAN)
        project_rbs.register_event_canfd_T_pre(OnCANPreFDevent)  # enable 回调函数 

        project_rbs.register_event_canfd_T_R(OnCANFDevent)  # enable 回调函数 
        project_rbs2.register_event_canfd_T_pre(OnCANPreFDevent_PCAN_Front)
        project_rbs.connect_application()
        project_rbs.RBS_Config(Set_up.NetName,Set_up.EnableNode)
        project_rbs.start_rbs()
        
        #电源
        project_rbs.write_db_signal(Set_up.NetName,Set_up.nodeName,'PEPS_0x1B1','PwrModVld',2)  #设置信号初
        project_rbs.write_db_signal(Set_up.NetName,Set_up.nodeName,'PEPS_0x1B1','PwrMod',2)     # IGN ON
        #车速
        project_rbs.write_db_signal(Set_up.NetName,Set_up.nodeName,'PBM_0x185','VehSpdVld',1)   #车速信号有效位 
        project_rbs.write_db_signal(Set_up.NetName,Set_up.nodeName,'PBM_0x185','VehSpd',0)      #车速
        project_rbs.write_db_signal(Set_up.NetName,Set_up.nodeName,'PBM_0x185','VehStop',1)     #车辆停止状态位   
        #档位
        project_rbs.write_db_signal(Set_up.NetName,Set_up.nodeName,'VCU_PDCU_0x230','VCU_STRATEGY_SHIFT_POSN_FLAG',0) #挡位信号有效位 
        project_rbs.write_db_signal(Set_up.NetName,Set_up.nodeName,'VCU_PDCU_0x230','VCU_STRATEGY_SHIFT_POSITION',1)  #档位


        __Driver['CAN'] = project_rbs
        logging.info("open CAN_Driver success".center(50, '-'))
        __Driver['CAN2'] = project_rbs2
        logging.info("open CAN_Driver2 success".center(50, '-'))


    except Exception as e:
        logging.info(traceback.logging.info_exc())
        __Driver['CAN'].app.disconnect()
        logging.info("open CAN_Driver failed".center(50, '-'))
        __Driver['CAN2'].app.disconnect()
        logging.info("open CAN_Driver2 failed".center(50, '-'))

    # Init UDS support
    try:
        if Set_up.CAN_Type == 'CAN':
            SupportFD = 0
            Maxdlc = 8
        else:
            SupportFD = 1
            Maxdlc = 15

        
        diag2 = TSCAN_UDS(ASupportFD=SupportFD, AMaxdlc=Maxdlc, reqID=Set_up.vehicle_type_key_Tab['RRCR']['req_ID'],resID=Set_up.vehicle_type_key_Tab['RRCR']['res_ID'],AFctID=Set_up.AFctID)
        diag3 = TSCAN_UDS(ASupportFD=SupportFD, AMaxdlc=Maxdlc, reqID=Set_up.vehicle_type_key_Tab['LRCR']['req_ID'],resID=Set_up.vehicle_type_key_Tab['LRCR']['res_ID'],AFctID=Set_up.AFctID)
        diagfun = TSCAN_UDS(ASupportFD=SupportFD, AMaxdlc=Maxdlc, reqID=Set_up.AFctID,resID=Set_up.vehicle_type_key_Tab['RRCR']['res_ID'],AFctID=Set_up.AFctID)
        
        
        diagfunRR = TSCAN_UDS(ASupportFD=SupportFD, AMaxdlc=Maxdlc, reqID=Set_up.AFctID,resID=Set_up.vehicle_type_key_Tab['RRCR']['res_ID'],AFctID=Set_up.AFctID)
        diagfunLR = TSCAN_UDS(ASupportFD=SupportFD, AMaxdlc=Maxdlc, reqID=Set_up.AFctID,resID=Set_up.vehicle_type_key_Tab['LRCR']['res_ID'],AFctID=Set_up.AFctID)
       


            
        if Set_up.act_radar_type == 'RRCR':
            __Driver['UDS'] = diag2
            __Driver['UDSFun'] = diagfunRR
        elif Set_up.act_radar_type == 'LRCR':
            __Driver['UDS'] = diag3
            __Driver['UDSFun'] = diagfunLR

        __Driver['UDSFun'] = diagfun
        __Driver['UDSRRCR'] = diag2
        __Driver['UDSLRCR'] = diag3
        __Driver['UDSFunRR'] = diagfunRR
        __Driver['UDSFunLR'] = diagfunLR
        # diag.req_and_res_can([0x22,0xf1,0x90],3)
        # diag.UDS_can_delete()
        logging.info("Creat UDS_Handle successful".center(50, '-'))
        pass
    except Exception as e:
        logging.info("Creat UDS_Handle failed ".center(50, '-'))
        pass

    # Init Power supply
    try:
        logging.info("open power_Driver".center(50, '-'))
        project_power = power(source=Set_up.source,baudrate=Set_up.baudrate)
        project_power.config()
        project_power.Enable(True)
        v,i =project_power.Read_Measure()
        project_power.set_vltage(12)
        __Driver['power'] = project_power
        time.sleep(1)
        logging.info("open power_Driver success".center(50, '-'))
    except Exception as e:
        logging.info(traceback.logging.info_exc())
        try:
            __Driver['power'].close()
        except Exception as e: 
            pass  
        logging.info("open power_Driver failed ".center(50, '-'))
    
    __Driver['CAN'].wakeup_ctrl(True)
    time.sleep(2)

    yield __Driver
    time.sleep(2)
    # __Driver['CAN'].stop_FrANFrame_Cycle(a)
    # __Driver['CAN'].stop_FrANFrame_Cycle(b)
    # __Driver['CAN'].stop_FrANFrame_Cycle(d)
    # __Driver['CAN'].stop_FrANFrame_Cycle(e)
    # __Driver['CAN'].stop_FrANFrame_Cycle(f)
    # __Driver['CAN'].stop_FrANFrame_Cycle(g)
    # __Driver['CAN'].stop_FrANFrame_Cycle(ab)

    __Driver['CAN'].wakeup_ctrl(False)


    __Driver['UDS'].UDS_can_delete()
    
    if Set_up.act_radar_type == 'LFCR':
        __Driver['UDSRRCR'].UDS_can_delete()
        __Driver['UDSLRCR'].UDS_can_delete()

        # __Driver['UDSFunRR'].UDS_can_delete()
        # __Driver['UDSFunLR'].UDS_can_delete()
        # __Driver['UDSFunRF'].UDS_can_delete()

    elif Set_up.act_radar_type == 'RRCR':
        __Driver['UDSLRCR'].UDS_can_delete()



    elif Set_up.act_radar_type == 'LRCR':
        __Driver['UDSRRCR'].UDS_can_delete()
        __Driver['UDSFunRR'].UDS_can_delete()
    elif Set_up.act_radar_type == 'RFCR':
        __Driver['UDSRRCR'].UDS_can_delete()
        __Driver['UDSLRCR'].UDS_can_delete()


    __Driver['UDSFun'].UDS_can_delete()
    __Driver['UDSFunRR'].UDS_can_delete()
    __Driver['UDSFunLR'].UDS_can_delete()
    project_rbs.tsapp_stop_logging()

    __Driver['CAN'].dis_connect_application()
    logging.info("close CAN_Driver".center(50, '-'))

    try:
        __Driver['power'].close()
    except Exception as e: 
        pass  
    logging.info("close power_Driver".center(50, '-'))


    # _CAN_driver.send(1,0x101,[1,2,3,4,15,16,17,18])
    # msg = _CAN_driver.receive(0)
    # for m in msg:
    #     logging.info('ID {:x}'.format(m.ID))
    #     logging.info(*(m.Data))

@pytest.fixture()
def action():
    # blfname = datetime.datetime.now().strftime('%Y-%m-%d_%H_%M_%S') + '.blf'
    # # project_BLF_File_CAN = os.path.join(Set_up.root, f"blf\{blfname}")
    # # __Driver['CAN'].tsapp_start_logging(project_BLF_File_CAN)
    logging.info("测试用例开始".center(30, '*'))
    time.sleep(0.5)
    yield
    __Driver['power'].set_vltage(12)
    __Driver['CAN'].write_db_signal(Set_up.NetName, Set_up.nodeName, 'PBM_0x185', 'VehSpd', 0)
    time.sleep(0.3)
    __Driver['UDS'].req_and_res_can([0x10,0x01],2)
    time.sleep(0.5)
    # __Driver['CAN'].tsapp_stop_logging()
    logging.info("测试用例结束".center(30, '*'))

@pytest.fixture()
def unlock_App():
    pass
    yield
    __Driver['UDS'].req_and_res_can([0x10,0x01],2)
    time.sleep(0.5)
    __Driver['UDS'].req_and_res_can([0x10,0x03],2)
    time.sleep(0.5)
    seed = []
    uds_rep,size = __Driver['UDS'].req_and_res_can([0x27,0x01],2)
    if uds_rep[0:2] != [0x67,0x01]:
        time.sleep(12)
        __Driver['UDS'].req_and_res_can([0x10,0x03],2)
        time.sleep(0.5)
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x27,0x01],2)
    seed = uds_rep[2:]
    key = __Driver['CAN'].calcKey(seed)
    send_key = [0x27,0x02] + key
    uds_rep,size = __Driver['UDS'].req_and_res_can(send_key,len(send_key))

@pytest.fixture()
def unlock_Boot():
    pass
    yield
    __Driver['UDS'].req_and_res_can([0x10,0x01],2)
    time.sleep(0.5)
    __Driver['UDS'].req_and_res_can([0x10,0x03],2)
    time.sleep(0.5)
    __Driver['UDS'].req_and_res_can([0x31,0x01,0x02,0x03],4)
    time.sleep(0.5)
    __Driver['UDS'].req_and_res_can([0x10,0x02],2)
    time.sleep(1.5)
    seed = []
    uds_rep,size = __Driver['UDS'].req_and_res_can([0x27,0x11],2)
    if uds_rep[0:2] != [0x67,0x11]:
        time.sleep(12)
        __Driver['UDS'].req_and_res_can([0x10,0x03],2)
        time.sleep(0.5)
        __Driver['UDS'].req_and_res_can([0x31,0x01,0x02,0x03],4)
        time.sleep(0.5)
        __Driver['UDS'].req_and_res_can([0x10,0x02],2)
        time.sleep(1.5)
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x27,0x11],2)
    seed = uds_rep[2:]
    key = __Driver['CAN'].calcKey(seed, 3)
    send_key = [0x27,0x12] + key
    uds_rep,size = __Driver['UDS'].req_and_res_can(send_key,len(send_key))

@pytest.fixture()
def power_reset():
    __Driver['CAN'].stop_rbs()
    with allure.step('Step1:Request:设置电压为0'):
        __Driver['power'].set_vltage(0)
        logging.info("Test NM power set to 0V".center(30, '*'))
        time.sleep(2)
    with allure.step('Step2:Request:设置电压为12V'):
        __Driver['power'].set_vltage(12)
        time.sleep(5)
    yield
    __Driver['CAN'].start_rbs()

@pytest.fixture(scope='function',autouse=False)
def power_Undervoltage():
    with allure.step('Step1:Request:设置电压为8V,并等待2s'):
        __Driver['power'].set_vltage(8)
        time.sleep(2)
    yield
    with allure.step('Step1:Request:设置电压为0V,并等待2s,设置电压1V'):
        __Driver['power'].set_vltage(0)
        time.sleep(2)
        __Driver['power'].set_vltage(12)
        time.sleep(8)

@pytest.fixture(scope='function',autouse=False)
def power_Overvoltage():
    with allure.step('Step1:Request:设置电压为17V,并等待2s'):
        __Driver['power'].set_vltage(17)
        time.sleep(2)
    yield
    with allure.step('Step1:Request:设置电压为0V,并等待2s,设置电压1V'):
        __Driver['power'].set_vltage(0)
        time.sleep(2)
        __Driver['power'].set_vltage(12)
        time.sleep(8)

@pytest.fixture(scope='function',autouse=False)
def default_session():
    time.sleep(0.1)
    with allure.step('Step1:Request:[0x10,0x01], # Response:[0x50,0x01]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x01],2)
        with assume: assert uds_rep[0:6] == [0x50,0x01,0x00,0x32,0x00,0xC8]

@pytest.fixture(scope='function',autouse=False)
def extend_session():
    time.sleep(0.05)
    with allure.step('Step1:Request:[0x10,0x03], # Response:[0x50,0x03]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x03],2)
        with assume: assert uds_rep[0:2] == [0x50,0x03]
        # time.sleep(0.1)
    yield
    with allure.step('Step1:Request:[0x10,0x01], # Response:[0x50,0x01]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x01],2)
        # with assume: assert uds_rep[0:6] == [0x50,0x01,0x00,0x32,0x00,0xC8]
        # time.sleep(1)

@pytest.fixture(scope='function',autouse=False)
def programming_session():
    time.sleep(0.1)
    with allure.step('Step1:Request:[0x10,0x03], # Response:[0x50,0x03]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x03],2)
        with assume: assert uds_rep[0:2] == [0x50,0x03]
    with allure.step('Step2:Request:[0x31,0x01,0x02,0x03], # Response:[0x51,0x01,0x02,0x03]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x31,0x01,0x02,0x03],4)
        with assume: assert uds_rep[0:4] == [0x71,0x01,0x02,0x03]
    time.sleep(0.05)
    with allure.step('Step3:Request:[0x10,0x02], # Response:[0x50,0x02]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x02],2)
        with assume: assert uds_rep[0:2] == [0x50,0x02]
    time.sleep(2.5)
    yield
    with allure.step('Step1:Request:[0x10,0x01], # Response:[0x50,0x01]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x01],2)
        with assume: assert uds_rep[0:6] == [0x50,0x01,0x00,0x32,0x00,0xC8]
        time.sleep(1)


@pytest.fixture(scope='function',autouse=False)
def programming_unlock():
    time.sleep(0.05)
    with allure.step('Step1:Request:[0x10,0x03], # Response:[0x50,0x03]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x03],2)
        with assume: assert uds_rep[0:2] == [0x50,0x03]
    with allure.step('Step2:Request:[0x31,0x01,0x02,0x03], # Response:[0x51,0x01,0x02,0x03]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x31,0x01,0x02,0x03],4)
        with assume: assert uds_rep[0:4] == [0x71,0x01,0x02,0x03]
    time.sleep(0.5)
    with allure.step('Step3:Request:[0x10,0x02], # Response:[0x50,0x02]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x02],2)
        with assume: assert uds_rep[0:2] == [0x50,0x02]
        time.sleep(2)
    seed = []
    with allure.step("Step4:Request:0x27,0x11, # Response:0x67,0x11"):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x27,0x11],2)
        if  uds_rep[0:2] != [0x67,0x11]:
         actuRespStr = binascii.b2a_hex(bytearray(uds_rep), ' ')  
         logging.error(f'correct response:[0x67,0x11], actual response:[{actuRespStr}]')
        with assume: assert (uds_rep[0:2] == [0x67,0x11] and size == 18)
    
        seed = uds_rep[2:]
        logging.info(f'seed:{seed}')
    
        key = __Driver['CAN'].calcKey(seed,level=3)
        send_key = [0x27,0x12] + key
    with allure.step("Step5:Request:{0}, # Response:0x67,0x12".format(send_key)):
        uds_rep,size = __Driver['UDS'].req_and_res_can(send_key,len(send_key))
        if  uds_rep[0:2] != [0x67,0x12]:
         actuRespStr = binascii.b2a_hex(bytearray(uds_rep), ' ')  
         correct_send_key = binascii.b2a_hex(bytearray(send_key), ' ')  
         logging.error(f'correct response:[{correct_send_key}], actual response:[{actuRespStr}]')
        with assume: assert uds_rep[0:2] == [0x67,0x12]
    time.sleep(0.5)
    with allure.step('Step6:Request:[0x10,0x01], # Response:[0x50,0x01]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x01],2)
        with assume: assert uds_rep[0:6] == [0x50,0x01,0x00,0x32,0x00,0xC8]
        time.sleep(1)
    with allure.step('Step7:Request:[0x10,0x03], # Response:[0x50,0x03]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x03],2)
        with assume: assert uds_rep[0:2] == [0x50,0x03]
    with allure.step('Step8:Request:[0x31,0x01,0x02,0x03], # Response:[0x51,0x01,0x02,0x03]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x31,0x01,0x02,0x03],4)
        with assume: assert uds_rep[0:4] == [0x71,0x01,0x02,0x03]
    time.sleep(0.5)
    with allure.step('Step9:Request:[0x10,0x02], # Response:[0x50,0x02]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x02],2)
        with assume: assert uds_rep[0:2] == [0x50,0x02]
    time.sleep(1)
    yield
    with allure.step('Step1:Request:[0x10,0x01], # Response:[0x50,0x01]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x01],2)
        with assume: assert uds_rep[0:6] == [0x50,0x01,0x00,0x32,0x00,0xC8]
        time.sleep(1)

@pytest.fixture(scope='function',autouse=False)
def extend_unlock():
    time.sleep(0.05)
    with allure.step('Step1:Request:[0x10,0x03], # Response:[0x50,0x03]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x03],2)
    seed = []
    with allure.step("Step2:Request:0x27,0x01, # Response:0x67,0x01"):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x27,0x01],2)
        if  uds_rep[0:2] != [0x67,0x01]:
            time.sleep(12)
            uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x03],2)
            time.sleep(0.5)
            uds_rep,size = __Driver['UDS'].req_and_res_can([0x27,0x01],2)
            if  uds_rep[0:2] != [0x67,0x01]:
                actuRespStr = binascii.b2a_hex(bytearray(uds_rep), ' ')  
                logging.error(f'correct response:[0x67,0x01], actual response:[{actuRespStr}]')
        with assume: assert (uds_rep[0:2] == [0x67,0x01] and size == 18)
    
        seed = uds_rep[2:]
        logging.info(f'seed:{seed}')
        key = __Driver['CAN'].calcKey(seed)
        send_key = [0x27,0x02] + key
    with allure.step("Step3:Request:{0}, # Response:0x67,0x02".format(send_key)):
        uds_rep,size = __Driver['UDS'].req_and_res_can(send_key,len(send_key))
        if  uds_rep[0:2] != [0x67,0x02]:
         actuRespStr = binascii.b2a_hex(bytearray(uds_rep), ' ')  
         correct_send_key = binascii.b2a_hex(bytearray(send_key), ' ')  
         logging.error(f'correct response:[{correct_send_key}], actual response:[{actuRespStr}]')
        with assume: assert uds_rep[0:2] == [0x67,0x02]
    with allure.step('Step1:Request:[0x10,0x01], # Response:[0x50,0x01]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x01],2)
        with assume: assert uds_rep[0:6] == [0x50,0x01,0x00,0x32,0x00,0xC8]
        time.sleep(1)
    with allure.step('Step1:Request:[0x10,0x03], # Response:[0x50,0x03]'):
        uds_rep,size = __Driver['UDS'].req_and_res_can([0x10,0x03],2)
        with assume: assert uds_rep[0:2] == [0x50,0x03]

@pytest.fixture()
def sleep_mode():
    with allure.step("Step1:上电后等待5s,满足radar睡眠条件"):
         time.sleep(5)

@pytest.fixture()
def env_initial():
    time.sleep(0.5)
    __Driver['CAN'].wakeup_ctrl(False)
    yield
    __Driver['CAN'].write_db_signal(Set_up.NetName,Set_up.nodeName,'PEPS_0x1B1','PwrMod',0)
    time.sleep(0.5)
    __Driver['CAN'].write_db_signal(Set_up.NetName,Set_up.nodeName,'BCM_0x2F1','BCM1_St_LFDoorLock',0)
    __Driver['CAN'].write_db_signal(Set_up.NetName,Set_up.nodeName,'BCM_0x2F1','BCM1_St_PasDoorLock',0)
    __Driver['CAN'].write_db_signal(Set_up.NetName,Set_up.nodeName,'BDC_BCM_2','BCM2_St_LRDoorLock',0)
    __Driver['CAN'].write_db_signal(Set_up.NetName,Set_up.nodeName,'BDC_BCM_2','BCM2_St_RRDoorLock',0)
    __Driver['CAN'].wakeup_ctrl(False)
    time.sleep(1.5)


# @pytest.fixture(scope=“class”,autouse=True)
@pytest.fixture(scope='module',autouse=False)
def power_reset_for_class():
    with allure.step('Step1:Request:设置电压为0V,并等待1s'):
        __Driver['power'].set_vltage(0)
        logging.info('power reset for module')
    time.sleep(1)
    with allure.step('Step2:Request:设置电压为14V'):
        __Driver['power'].set_vltage(14)
    time.sleep(8)

def pytest_configure(config):
    # Add interface address and project info
    #TODO, below info import from common folder Comm_Config.py file
    config._metadata["Software version"] = Set_up.ECUSoftwareversionnumber1
    config._metadata["internal version"] = Set_up.internalver1
    config._metadata["PartNumber"] = Set_up.PartNumber1
    config._metadata["HardwareVersionNumber"] = Set_up.HardwareVersionNumber1
    config._metadata["Test time"] = datetime.date.today()

    # Delete Java_Home
    config._metadata.pop("Python")
    config._metadata.pop("Plugins")
    config._metadata.pop("Packages")


@pytest.mark.optionalhook
def pytest_html_results_summary(prefix, summary, postfix):
    prefix.extend([html.p("Tester: YangLiang")])
    prefix.extend([html.p("Report version: 0.0.1")])


@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
    cells.pop()

@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
    cells.pop()

@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()


@pytest.fixture(scope="function", autouse=True)
def mod_header(request):
    item_name = request.node.nodeid.split("::")[-1]
    logging.info('\n-----------------')
    logging.info('Item name : %s' % item_name)
    blfname = datetime.datetime.now().strftime('%Y-%m-%d_%H_%M_%S') + '.blf'
    __Driver['CAN'].tsapp_start_logging(os.path.join(Set_up.root, f"blflog\{item_name}_{blfname}"))
    yield
    __Driver['CAN'].tsapp_stop_logging()